package com.chalmers.irc2you.model;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Observer;
import android.database.Observable;

/**
 * 
 * @author Scott
 * 
 */
public class ChannelList extends Observable<Observer> {

	private static ChannelList INSTANCE = null;
	private LinkedList<Channel> channels = new LinkedList<Channel>();

	/**
	 * Constructor
	 */
	private ChannelList() {
	}

	/**
	 * 
	 * @return Returns the instance of ChannelList
	 */
	public static ChannelList getInstance() {
		if (INSTANCE == null) {
			INSTANCE = new ChannelList();
		}
		return INSTANCE;
	}

	/**
	 * 
	 * @param channel
	 *            The channel where the message will be added
	 * @param msg
	 *            The message that is to be added
	 */
	protected void addMessage(Channel channel, Message msg) {
		channel.addMessage(msg);
	}

	/**
	 * 
	 * @param channel
	 *            The channel that will be added
	 * @param obs
	 *            The observer for the specified channel
	 */
	protected void addChannel(Channel channel) {
		channels.add(channel);// add the channel to the LinkedList
	}

	/**
	 * 
	 * @param channel
	 *            The channel that is to be removed
	 */
	protected void removeChannel(Channel channel) {
		channels.remove(channel);
	}
	/**
	 * Returns a channel with the given name
	 * @param channel The name of the channel
	 * @return The channel object
	 */
	protected Channel getChannel(String channel) {
		for (int i = 0; i<channels.size(); i++) { // check if there is a
														// channel with that
														// name
			if (channel.equals(channels.get(i).getName()))
				return (channels.get(i));
		}
		return null;
	}
	/**
	 * get all channels
	 * @return Returns all channels
	 */
	protected LinkedList<Channel> getAllChannels(){
		return channels;
	}
	/**
	 * removes all channels from the ChannelList
	 */
	protected void clearAll(){
		channels.clear();
	}

}
